package bma.common.netty.webserver.ai;

import bma.common.langutil.ai.vm.AIVM.Pickable;
import bma.common.langutil.ai.vm.AIVM.Picker;
import bma.common.netty.webserver.RequestContext;
import bma.common.netty.webserver.SessionManager;

public class SessionRouter4AI implements RequestRouter4AI {

	protected SessionManager sessionManager;

	public SessionManager getSessionManager() {
		return sessionManager;
	}

	public void setSessionManager(SessionManager sessionManager) {
		this.sessionManager = sessionManager;
	}

	public SessionRouter4AI() {
		super();
	}

	public SessionRouter4AI(SessionManager sessionManager) {
		super();
		this.sessionManager = sessionManager;
	}

	@Override
	public Object apply(RequestContext ctx) {
		final String sid = sessionManager.getSessionId(ctx.getRequest());
		if (sid == null) {
			return null;
		}
		return new Pickable() {

			@Override
			public int hashCode() {
				return sid.hashCode();
			}

			@Override
			public Picker getPicker() {
				return Picker.HASH;
			};

		};
	}
}
